﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CodeCamp.Models.Volunteers;

namespace CodeCamp.Controllers
{
  public class VolunteersController : Controller
  {

    private VolunteerIndexViewModel GetVolunteerIndexViewModel( string eventName )
    {
      int eventId = EventsHelper.GetEventId( eventName );
      var repository = new CodeCampDataRepository();
      var eventDisplayName = repository.GetEvent( eventId ).DisplayName;

      return new VolunteerIndexViewModel { EventDisplayName = eventDisplayName };
    }

    // Volunteer/Index

    public ActionResult Index( string eventName )
    {
      return View( GetVolunteerIndexViewModel( eventName ) );
    }

    // Volunteer

    public ActionResult List( string eventName )
    {
      return View( "Index", GetVolunteerIndexViewModel( eventName ) );
    }

    //public ActionResult List( string eventName )
    //{
    //  int eventId = EventsHelper.GetEventId( eventName );
    //  var repository = new CodeCampDataRepository();
    //  var eventDisplayName = repository.GetEvent( eventId ).DisplayName;

    //  var tasks = repository.GetTasks( eventId );

    //  var taskList = new List<VolunteerListViewModel.Task>();
    //  foreach ( var task in tasks )
    //  {
    //    var timeList = new List<VolunteerListViewModel.Task.Time>();
    //    foreach ( var timeslot in task.Tasks_Timeslots )
    //    {
    //      var ts = timeslot.TaskTimeslot;
    //      timeList.Add( 
    //        new VolunteerListViewModel.Task.Time
    //        {
    //          Date = ts.Date,
    //          StartTime = ts.StartTime,
    //          EndTime = ts.EndTime,
    //          VolunteersStillNeeded = ts.VolunteersNeeded
    //        } );
    //    }
    //    taskList.Add(
    //      new VolunteerListViewModel.Task
    //      {
    //        Name = task.Name,
    //        Notes = task.Notes,
    //        Times = timeList
    //      } );
    //  }

    //  var model = new VolunteerListViewModel
    //  {
    //    EventDisplayName = eventDisplayName,
    //    Tasks = taskList
    //  };

    //  return View( model );
    //}

  }
}
